"""
get real time data from OPCUA server
author:zjf
datetime:4-28
"""
import opcua


class OPCUAClient(object):
    def __init__(self, host, port):
        self._url = f"opc.tcp://{host}:{port}"

    def read(self, nodes:list) -> tuple:
        c = opcua.Client(url=self._url)
        try:
            c.connect()
            res = c.get_values(nodes)
            return res
        except Exception as e:
            return ('error', e)
        finally:
            c.disconnect()
